home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_x / xcoral16.zip / CLASS_DI.C < prev    next >
C/C++ Source or Header  |  1993-01-15  |  7KB  |  241 lines

  1. /*
  2. ** Copyright 1989, 1992 by Lionel Fournigault
  3. **
  4. ** Permission to use, copy, and distribute for non-commercial purposes,
  5. ** is hereby granted without fee, providing that the above copyright
  6. ** notice appear in all copies and that both the copyright notice and this
  7. ** permission notice appear in supporting documentation.
  8. ** The software may be modified for your own purposes, but modified versions
  9. ** may not be distributed.
  10. ** This software is provided "as is" without any expressed or implied warranty.
  11. **
  12. **
  13. */
  14.  
  15. #include "result_types.h"
  16. #include "file_dict.h"
  17. #include "class_dict.h"
  18. #include "browser_util.h"
  19. #include <string.h>
  20. #include <stdio.h>
  21.  
  22.  
  23. /*------------------------------------------------------------------------------
  24. //                         Le dictionnaire des classes
  25. //------------------------------------------------------------------------------
  26. */
  27.  
  28. ClassRec*  class_dict[CLASS_DICT_SIZE];
  29.  
  30. int        class_count = 0;
  31.  
  32.  
  33. /*------------------------------------------------------------------------------
  34. */
  35. ClassRec* create_class (class_name)
  36.   char* class_name;
  37. {
  38.     ClassRec**  head;
  39.   ClassRec*   current_class;
  40.   int         x_size;
  41.  
  42.     get_head_Rec(class_name, class_dict, CLASS_DICT_SIZE, head);
  43.   search_Rec(class_name, ClassRec, head, current_class);
  44.   if (current_class == Null) {
  45.     x_size = sizeof(ClassRec) + CLASS_PLENGTH + strlen(class_name) + 1;
  46.     current_class = (ClassRec*) xmalloc(x_size);
  47.     if (current_class != Null) {
  48.       create_Rec(class_name, ClassRec, head, current_class, CLASS_PREFIX, CLASS_PLENGTH);
  49.       current_class->_decl_file     = Null;
  50.         current_class->_decl_line     = 0;
  51.         current_class->_parents_list  = Null;
  52.         current_class->_parents_count = 0;
  53.         current_class->_methods_list  = Null;
  54.         current_class->_next_marked   = Null;
  55.              class_count++;
  56.         }
  57.     }
  58.   return(current_class);
  59. }
  60.  
  61.  
  62. /*------------------------------------------------------------------------------
  63. */
  64. ClassRec* find_class(class_name)
  65.   char* class_name;
  66. {
  67.     ClassRec**  head;
  68.   ClassRec*   current_class;
  69.  
  70.     get_head_Rec(class_name, class_dict, CLASS_DICT_SIZE, head);
  71.   search_Rec(class_name, ClassRec, head, current_class);
  72.   return(current_class);
  73. }
  74.  
  75.  
  76. /*------------------------------------------------------------------------------
  77. */
  78. typedef long Bits;
  79.  
  80. #define LAST_BIT  ((sizeof(Bits) * 8) - 1)
  81.  
  82. static Bits erazed_bits[(CLASS_DICT_SIZE + LAST_BIT) / (LAST_BIT + 1)];
  83.  
  84.  
  85. void class_eraze_file(file_name)
  86.     char* file_name;
  87. {
  88.   Bits*      erazed_slice;
  89.   FileRec*   current_file;
  90.   ClassRec*  current_class;
  91.   MethodRec* current_method;
  92.   ParentRec* current_parent;
  93.   int        index;
  94.  
  95.   current_file = find_file(file_name);
  96.   if (current_file != Null) {
  97.     erazed_slice = erazed_bits;
  98.     for (index = 0; index < CLASS_DICT_SIZE; index++) {
  99.       current_class = class_dict[index];
  100.       while (current_class != Null) {
  101.         if (current_class->_decl_file == current_file) {
  102.           current_class->_decl_file     = Null;
  103.           current_class->_decl_line     = 0;
  104.           current_class->_parents_count = 0;
  105.           current_parent = current_class->_parents_list;
  106.           while (current_parent != Null) {
  107.             current_parent->_scope = UNKNOWN_SCOPE;
  108.             current_parent         = current_parent->_next;
  109.           }
  110.           (*erazed_slice) |= ((0x00000001L) << (index & LAST_BIT));
  111.         }
  112.         current_method = current_class->_methods_list;
  113.         while (current_method != Null) {
  114.           if (current_method->_decl_file == current_file) {
  115.             current_method->_decl_file = Null;
  116.             current_method->_decl_line = 0;
  117.             (*erazed_slice) |= ((0x00000001L) << (index & LAST_BIT));
  118.           }
  119.           if (current_method->_impl_file == current_file) {
  120.             current_method->_impl_file = Null;
  121.             current_method->_impl_line = 0;
  122.             (*erazed_slice) |= ((0x00000001L) << (index & LAST_BIT));
  123.           }
  124.           current_method = current_method->_next;
  125.         }
  126.           current_class = current_class->_next;
  127.       }
  128.       if ((index & LAST_BIT) == LAST_BIT)
  129.         erazed_slice++;
  130.     }
  131.   }  
  132. }
  133.  
  134.  
  135. /*------------------------------------------------------------------------------
  136. */
  137. void garbage_class()
  138. {
  139.   Bits*      erazed_slice;
  140.   ClassRec*  previous_class;
  141.   ClassRec*  current_class;
  142.   ClassRec*  next_class;
  143.   MethodRec* previous_method;
  144.   MethodRec* current_method;
  145.   MethodRec* next_method;
  146.   ParentRec* previous_parent;
  147.   ParentRec* current_parent;
  148.   ParentRec* next_parent;
  149.   int        index;
  150.  
  151.   erazed_slice = erazed_bits;
  152.   for (index = 0; index < CLASS_DICT_SIZE; index++) {
  153.     if ((*erazed_slice) == 0) {
  154.       index += LAST_BIT;
  155.       erazed_slice++;
  156.     }
  157.     else {
  158.       if (((*erazed_slice) & ((0x00000001L) << (index & LAST_BIT))) != 0) {
  159.         previous_class = Null;
  160.         current_class  = class_dict[index];
  161.         while (current_class != Null) {
  162.           previous_method = Null;
  163.           current_method  = current_class->_methods_list;
  164.           while (current_method != Null) {
  165.             if (   (current_method->_decl_file == Null)
  166.                 && (current_method->_impl_file == Null)) {
  167.               next_method = current_method->_next;
  168.               if (previous_method == Null)
  169.                 current_class->_methods_list = next_method;
  170.               else
  171.                 previous_method->_next       = next_method;
  172.               free(current_method);
  173.               current_method = next_method;
  174.             }
  175.             else {
  176.               previous_method = current_method;
  177.               current_method  = current_method->_next;
  178.             }
  179.           }
  180.           previous_parent = Null;
  181.           current_parent  = current_class->_parents_list;
  182.           while (current_parent != Null) {
  183.             if (current_parent->_scope == UNKNOWN_SCOPE) {
  184.               next_parent = current_parent->_next;
  185.               if (previous_parent == Null)
  186.                 current_class->_parents_list = next_parent;
  187.               else
  188.                 previous_parent->_next       = next_parent;
  189.               free(current_parent);
  190.               current_parent = next_parent;
  191.             }
  192.             else {
  193.               previous_parent = current_parent;
  194.               current_parent  = current_parent->_next;
  195.             }
  196.           }
  197.           if (   (current_class->_methods_list == Null)
  198.               && (current_class->_decl_file    == Null)) {
  199.             next_class = current_class->_next;
  200.             if (previous_class == Null)
  201.               class_dict[index]     = next_class;
  202.             else
  203.               previous_class->_next = next_class;
  204.             --class_count;
  205.             free(current_class);
  206.             current_class = next_class;
  207.           }
  208.           else {
  209.             previous_class = current_class;
  210.                current_class  = current_class->_next;
  211.             }
  212.         }
  213.       }
  214.       if ((index & LAST_BIT) == LAST_BIT) {
  215.         *erazed_slice = 0;
  216.         erazed_slice++;
  217.       }
  218.     }
  219.   }
  220. }
  221.  
  222.  
  223. /*------------------------------------------------------------------------------
  224. */
  225. void init_class() {
  226.   Bits* erazed_slice;
  227.   int   index;
  228.  
  229.   erazed_slice = erazed_bits;
  230.   for (index = 0; index < CLASS_DICT_SIZE; index++) {
  231.     if ((index & LAST_BIT) == LAST_BIT) {
  232.       *erazed_slice = 0;
  233.       erazed_slice++;
  234.     }
  235.     class_dict[index] = Null;
  236.   }
  237. }
  238.  
  239.  
  240.  
  241.